package com.ssfGame.puremvc.view.module.title
{
	import api.event.CustomEvent;
	
	import com.game.utils.GlobalFun;
	import com.ssfGame.puremvc.StaticConst;
	import com.ssfGame.puremvc.view.application.SceneLayerMediator;
	import com.ssfGame.puremvc.view.module.ModuleVC;
	import com.ssfGame.puremvc.view.module.title.vc.TitleVC;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class TitleMediator extends Mediator
	{
		
		public static const NAME:String="TitleMediator";
		private var _titleVC:TitleVC;
		public function TitleMediator(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
		}
		override public function listNotificationInterests():Array{
			return [
				StaticConst.N_M_TITLE_ADD,
				StaticConst.N_M_TITLE_DEL
			]
		}
		override public function handleNotification(notification:INotification):void{
			switch(notification.getName()){
				case StaticConst.N_M_TITLE_ADD:
					sendNotification(StaticConst.N_M_SCENE_LAYER_DEL,null,SceneLayerMediator.DEL_ALL);
					if(_titleVC==null){
						_titleVC=new TitleVC();
						_titleVC.addEventListener(ModuleVC.TO_MEDIATOR,recEvent);
					}
					sendNotification(StaticConst.N_M_SCENE_LAYER_ADD,_titleVC);
					break
				case StaticConst.N_M_TITLE_DEL:
					gc();
					break;
			}
		}
		private function recEvent(e:CustomEvent):void{
			switch(e.type){
				case TitleVC.INIT_PVP:
					gc();
					sendNotification(StaticConst.N_C_INIT_PVP_API);
					break
			}
		}
		private function gc():void{
			if(_titleVC!=null){
				sendNotification(StaticConst.N_M_SCENE_LAYER_DEL,_titleVC);
				_titleVC.removeEventListener(ModuleVC.TO_MEDIATOR,recEvent);
				_titleVC.gc();
				_titleVC=null;	
			}
			
		}
		public function get titleVC():TitleVC{
			return viewComponent as TitleVC;
		}
	}
}